package cc.kzc.adminauth.exception;

import cc.kzc.adminauth.common.BaseResponse;
import cc.kzc.adminauth.common.ErrorCode;

public class BaseError extends RuntimeException {
	private static final long serialVersionUID = 2773143726767092656L;

	protected ErrorCode errorCode;

	public BaseError(ErrorCode errorCode) {
		super();
		this.errorCode = errorCode;
	}

	public BaseError(ErrorCode errorCode, String message) {
		super(message);
		this.errorCode = errorCode;
	}

	public BaseResponse toResponse() {
		BaseResponse resp = null;
		if (null == errorCode) {
			resp = BaseResponse.fail(getMessage());
		} else {
			resp = BaseResponse.fail(errorCode, getMessage());
		}
		return resp;
	}

}
